package net.stogi.unicore.beyond.io.client.output.filedownloadfield;

import com.extjs.gxt.ui.client.widget.form.FileUploadField;
import com.google.gwt.user.client.ui.Widget;

import net.stogi.unicore.beyond.api.model.OutputDefinition;
import net.stogi.unicore.beyond.io.client.output.core.OutputField;

public class FileDownloadOutputField implements OutputField {

	protected final FileUploadField field = new FileUploadField();

	protected OutputDefinition outputDefinition;

	public FileDownloadOutputField(OutputDefinition outputDefinition) {
		this(outputDefinition.getOutputType().getName());
		this.outputDefinition = outputDefinition;
		initField();
	}

	@SuppressWarnings("unused")
	private FileDownloadOutputField() {}

	private FileDownloadOutputField(String outputTypeName) {
		if (!"filedownloadfield".equals(outputTypeName)) {
			throw new IllegalArgumentException("Output definition is not type of 'filedownloadfield'");
		}
	}

	@Override
	public Widget asWidget() {
		return field;
	}

	private void initField() {
		field.setFieldLabel(outputDefinition.getName());
	}
}
